package cn.szsys.integration.ex;

import cn.szsys.integration.ex.enums.ExceptionEnum;
import com.alibaba.fastjson2.JSON;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serial;

/**
 * 业务异常，主要表示业务上不满足需求，如参数错误等
 * 
 * @author 50364
 *
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class BusinessException extends BaseException {

	@Serial
	private static final long serialVersionUID = -5854896782817706871L;

	private String params;

	/**
	 * @param ee
	 * @param reqParams 请求参数
	 */
	public BusinessException(ExceptionEnum ee, Object... reqParams) {
		super(ee);
		this.params = JSON.toJSONString(reqParams);
		//logger.error("业务异常，原因:" + ee.getMsg() + ", 入参：" + this.params);
	}

	public BusinessException(String reason, Object... reqParams) {
		super(reason);
		super.code = ExceptionEnum.OP_FAIL.getCode();
		super.reason = reason;
		this.params = "";
//		if (reqParams.length > 0){
//			this.params = JSONObject.toJSONString(reqParams);
//		}else {
//			this.params = "";
//		}
		//logger.error("业务异常，原因:" + errMsg + ", 入参：" + this.params);
	}
	
	public BusinessException(String reason, Exception ex) {
		super(reason, ex);
		super.code = ExceptionEnum.OP_FAIL.getCode();
		super.reason = reason;
		this.params = "";
		//logger.error("业务异常，原因:" + errMsg + ", 入参：" + this.params);
	}

	protected BusinessException() {
		super();
	}

	@Override
	public String toString() {
		return "BusinessException [params=" + params + ", code=" + code + ", reason=" + reason + "]";
	}
}
